package com.pega.tulokhorecord.data.database;

import java.sql.SQLException;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;
import com.pega.tulokhorecord.data.SetInfo;
import com.pega.tulokhorecord.data.TurnInfo;

public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
	// name of the database file for your application -- change to something
	// appropriate for your app
	private static final String DATABASE_NAME = "eprescription_database";

	// any time you make changes to your database objects, you may have to
	// increase the database version
	private static final int DATABASE_VERSION = 1;

	private Dao<SetInfo, Integer> SetInfoDao = null;
	private Dao<TurnInfo, Integer> TurnInfoDao = null;

	public DatabaseHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase arg0, ConnectionSource connectionSource) {
		// TODO Auto-generated method stub
		try {
			TableUtils.createTable(connectionSource, SetInfo.class);
			TableUtils.createTable(connectionSource, TurnInfo.class);
		} catch (SQLException e) {
			// Log.e(DatabaseHelper.class.getName(), "Can't create database",
			// e);
			throw new RuntimeException(e);
		}
	}

	public Dao<SetInfo, Integer> getSetInfoDao() {
		if (null == SetInfoDao) {
			try {
				SetInfoDao = getDao(SetInfo.class);
			} catch (java.sql.SQLException e) {
				e.printStackTrace();
			}
		}
		return SetInfoDao;
	}

	public Dao<TurnInfo, Integer> getTurnInfoDao() {
		if (null == TurnInfoDao) {
			try {
				TurnInfoDao = getDao(TurnInfo.class);
			} catch (java.sql.SQLException e) {
				e.printStackTrace();
			}
		}
		return TurnInfoDao;
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, ConnectionSource arg1, int arg2,
			int arg3) {
		// TODO Auto-generated method stub

	}
}
